<?php
// Set default timezone
date_default_timezone_set("America/Montreal");

// Error reporting
error_reporting(E_ALL);  
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);

// Load libraries
set_include_path('./library/'  . PATH_SEPARATOR . './application/views/scripts/includes/'  .  PATH_SEPARATOR . './application/models/' . PATH_SEPARATOR . './js/'  . PATH_SEPARATOR . './css/' .PATH_SEPARATOR .'./application/views' .PATH_SEPARATOR . get_include_path());

// Zend's autoload
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

// Load DB, Debug, and Auth libraries
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Debug');
Zend_Loader::loadClass('Zend_Auth');
Zend_Loader::loadClass('Pledges');
Zend_Loader::loadClass('Security');

// Get config
$config = new Zend_Config_Ini('./application/config.ini','production');

// Create the registry
$registry = Zend_Registry::getInstance();

// setup database
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db', $db);

// Front controller
$frontController = Zend_Controller_Front::getInstance(); 

// Disable error handler 
$frontController->throwExceptions(true); 

$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route('pledges/:pledge_id',array('controller' => 'pledges','action' => 'index')); 
$router->addRoute('pledges', $route);
$route = new Zend_Controller_Router_Route('pledges/:pledge_id/validated',array('controller' => 'pledges','action' => 'validated')); 
$router->addRoute('pledges_validated', $route);
$route = new Zend_Controller_Router_Route('validate/:pledge_id',array('controller' => 'validate','action' => 'index')); 
$router->addRoute('validate', $route);
$route = new Zend_Controller_Router_Route('pledges/all',array('controller' => 'pledges','action' => 'all')); 
$router->addRoute('pledges_all', $route);


// Point the front controller to action controllers
$frontController->setControllerDirectory('./application/controllers'); 

// Register the error controller
$frontController->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(array(
    'module'     => 'error',
    'controller' => 'error',
    'action'     => 'error'
)));

// Let's go!
$frontController->dispatch(); 
